#! /usr/bin/python3
# encoding: utf-8

example_programs = {
    'jack_cpu_load' : 'cpu_load.c',
    'jack_latent_client' : 'latent_client.c',
    'jack_metro' : 'metro.c',
    'jack_midi_latency_test' : 'midi_latency_test.c',
    'jack_midiseq' : 'midiseq.c',
    'jack_midisine' : 'midisine.c',
    'jack_net_master' : 'netmaster.c',
    'jack_net_slave' : 'netslave.c',
    'jack_server_control' : 'server_control.cpp',
    'jack_showtime' : 'showtime.c',
    'jack_simdtests' : 'simdtests.cpp',
    'jack_simple_client' : 'simple_client.c',
    'jack_simple_session_client' : 'simple_session_client.c',
    'jack_thru' : 'thru_client.c',
    'jack_zombie' : 'zombie.c',
    }

example_libs = {
    'inprocess' : 'inprocess.c',
    }

def configure(conf):
    conf.env['BUILD_EXAMPLE_CLIENT_REC'] = conf.env['SNDFILE']

def build(bld):
    if bld.env['IS_LINUX']:
        os_incdir = ['../linux', '../posix']
    if bld.env['IS_MACOSX']:
        os_incdir = ['../macosx', '../posix']
    if bld.env['IS_SUN']:
        os_incdir = ['../solaris', '../posix']
    if bld.env['IS_WINDOWS']:
        os_incdir = ['../windows']
    for example_program, example_program_source in list(example_programs.items()):
        if example_program == 'jack_server_control':
            use = ['serverlib', 'STDC++']
        elif example_program == 'jack_net_slave':
            if not bld.env['BUILD_NETLIB']:
                continue
            use = ['netlib']
        elif example_program == 'jack_net_master':
            if not bld.env['BUILD_NETLIB']:
                continue
            use = ['netlib']
        else:
            use = ['clientlib']

        if bld.env['IS_MACOSX']:
            prog = bld(features='c cprogram', framework = ['Foundation'])
        else:
            prog = bld(features='c cprogram')
        prog.includes = os_incdir + ['../common/jack', '../common']
        prog.source = example_program_source
        prog.use = use
        if bld.env['IS_LINUX']:
            prog.use += ['RT', 'M']
        if bld.env['IS_SUN']:
            prog.use += ['M']
        if bld.env['IS_WINDOWS'] and bld.env['BUILD_STATIC']:
            prog.env['LIB_PTHREAD'] = [':libwinpthread.a']
        #prog.cflags = ['-Wno-deprecated-declarations', '-Wno-misleading-indentation']
        #prog.cxxflags = ['-Wno-deprecated-declarations', '-Wno-misleading-indentation']

        prog.target = example_program

    if bld.env['BUILD_EXAMPLE_CLIENT_REC']:
        prog = bld(features = 'c cprogram')
        prog.includes = os_incdir + ['../common/jack', '../common']
        prog.source = 'capture_client.c'
        prog.use = ['clientlib']
        if bld.env['IS_MACOSX']:
            prog.use += ['SNDFILE']
        if bld.env['IS_LINUX']:
            prog.use += ['RT', 'SNDFILE']
        if bld.env['IS_SUN']:
            prog.use += ['RT', 'SNDFILE']
        if bld.env['IS_WINDOWS']:
            prog.uselib = ['SNDFILE']
            if bld.env['BUILD_STATIC']:
                prog.env['LIB_PTHREAD'] = [':libwinpthread.a']
        prog.target = 'jack_rec'

    for example_lib, example_lib_source in list(example_libs.items()):
        lib = bld(features = 'c cshlib')
        if not bld.env['IS_WINDOWS']:
            lib.env['cshlib_PATTERN'] = '%s.so'
        lib.includes = os_incdir + ['../common/jack', '../common']
        lib.target = example_lib
        lib.source = example_lib_source
        if bld.env['IS_SUN']:
            lib.env.append_value('LINKFLAGS', '-lm')
        if bld.env['IS_WINDOWS'] and bld.env['BUILD_STATIC']:
            prog.env['LIB_PTHREAD'] = [':libwinpthread.a']
        lib.use = 'serverlib'
        lib.install_path = '${ADDON_DIR}/'
